package etp.server;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

import etp.client.Recurso;

/**
 * 
 * Classe de testes
 *
 */
public class TesteServlet extends HttpServlet {

	private static final long serialVersionUID = -6657500281300591639L;

	/**
	 * 
	 */
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
//		List<Projeto> ltp = AdminProjeto.listarProjeto();
//		PrintWriter output = new PrintWriter(resp.getOutputStream());
//
//		TarefaPersistente t = new TarefaPersistente("Tarefa OK", 1, new Date(2009, 02, 04), ltp.get(0).getCod());
//
//		AdminTarefa.criarTarefa(t);
//		
//		List<TarefaPersistente> ltt = new ArrayList<TarefaPersistente>();
//		
//		ltt = AdminTarefa.listarTarefaBy(4,ltp.get(0).getCod());
		
		 UserService userService = UserServiceFactory.getUserService();
	        User user = userService.getCurrentUser();

	        if (user != null) {
	        	
	        	Recurso recurso = AdminRecurso.getRecurso(user.getEmail());
	        	
	        	if(recurso != null){
		            resp.setContentType("text/plain");
		            resp.getWriter().println("Hello, " + user.getNickname());
		            
		            return;
	        	}
	        }
	        
	        resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
	        
	
	}

	
	
}
